import { _orderList } from "../../../service/api";

Page({
  data: {
    orderList: [],
    count: 0,
    page: 1,
    size: 10,
  },
  onLoad: function (options) {
    this.initData();
  },
  async initData() {
    const { page, size } = this.data;
    const res = await _orderList({ page, size });
    this.setData({
      orderList: [...this.data.orderList, ...res.list],
      count: res.count,
    });
  },
  handleReachBottom() {
    const { page, size, count } = this.data;
    if (page < Math.ceil(count / size)) {
      this.setData({ page: page + 1 });
      this.initData();
    }
  },
});
